package com.isunland.managesystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.volley.toolbox.ImageLoader;
import com.isunland.managesystem.R;
import com.isunland.managesystem.common.RequestManager;
import com.isunland.managesystem.entity.GuideMenu;
import java.util.List;

/**
 * 对象功能:  二级菜单adapter
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: HuXiaoDan
 * 创建时间: 2017/3/15 10:49
 */
public class GuideSecondListAdapter extends ArrayAdapter<GuideMenu> {

  /**
   * ViewHolder class for layout.<br />
   * <br />
   * Auto-created on 2017-03-15 10:57:19 by Android Layout Finder
   * (http://www.buzzingandroid.com/tools/android-layout-finder)
   */
  private static class ViewHolder {
    public final LinearLayout rootView;
    public final TextView tvGuideName;
    public final ImageView ivIcon;

    private ViewHolder(LinearLayout rootView, TextView tvGuideName, ImageView ivIcon) {
      this.rootView = rootView;
      this.tvGuideName = tvGuideName;
      this.ivIcon = ivIcon;
    }

    public static ViewHolder create(LinearLayout rootView) {
      TextView tvGuideName = (TextView) rootView.findViewById(R.id.tv_guideName);
      ImageView ivIcon = (ImageView) rootView.findViewById(R.id.iv_icon);
      return new ViewHolder(rootView, tvGuideName, ivIcon);
    }
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      View view = mInflater.inflate(R.layout.fragment_guide_second_item, parent, false);
      vh = ViewHolder.create((LinearLayout) view);
      view.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }

    GuideMenu item = getItem(position);

    vh.tvGuideName.setText(item.getResName());

    // icon
    //        String icon = item.getIcon();
    //        if (!TextUtils.isEmpty(icon)) {
    //            String urlImage = "http://192.168.1.8:8080/styles/default/images/resicon/template_edit.png";
    //            ImageLoader.ImageListener listener = ImageLoader.getImageListener(vh.ivIcon, // 控件名
    //                    R.drawable.forum_mypublish, R.drawable.forum_mypublish); // 默认头像
    //            mImageLoader.get(urlImage, listener);
    //        } else {
    vh.ivIcon.setImageResource(R.drawable.forum_mypublish);
    //        }

    return vh.rootView;
  }

  private LayoutInflater mInflater;
  private ImageLoader mImageLoader;

  // Constructors
  public GuideSecondListAdapter(Context context, List<GuideMenu> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
    this.mImageLoader = RequestManager.getImageLoader();
  }

  public GuideSecondListAdapter(Context context, GuideMenu[] objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
    this.mImageLoader = RequestManager.getImageLoader();
  }
}

